package com.zx.kitchen.index.common.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.zx.kitchen.index.common.base.ABasePagerAdapter;
import com.zx.kitchen.index.common.entity.BannerBean;

import java.util.List;

/**
 * Created by MDC-002 on 2016/6/27.
 */
public class BannerAdapter extends ABasePagerAdapter<BannerBean> {
    public BannerAdapter(List<BannerBean> data, Context context) {
        super(data, context);
    }


    @Override
    public View initView(ViewGroup container, final int position) {

        ImageView photoView = new ImageView(container.getContext());

        final String item = getItem(position).getUrl();
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        photoView.setLayoutParams(layoutParams);
        photoView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        Glide.with(getContext()).load(item).into(photoView);
        photoView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onButtonItemClick(v, position);
            }
        });

        return photoView;
    }

    /**
     * 单击事件监听器
     */
    protected OnButtonItemClickListener mListener = null;

    public interface OnButtonItemClickListener {
        void onButtonItemClick(View v, int position);
    }

    public void setOnButtonItemClick(OnButtonItemClickListener mListener) {
        this.mListener = mListener;
    }

}
